GLOBAL.setmetatable(env,{__index=function(t,k) return GLOBAL.rawget(GLOBAL,k) end}) --伟大，无需多言

local charname = "yunli"

PrefabFiles = {
	charname,  --人物代码文件
	charname.."_none",  --人物皮肤
    "i26_flower_sack",
    "i26_laotie",
    "i26_flower_sack",
    "i26_fx",
    "i26_skillpoint",
    "i26_food",
    "i26_jianmu_sapling",
    "i26_jianmu",
    "i26_warmth_debuff",
    "i26_hanbing_debuff",
    "i26_fangshui_debuff",
}

Assets = {
    Asset( "IMAGE", "images/saveslot_portraits/"..charname..".tex" ), --存档图片
    Asset( "ATLAS", "images/saveslot_portraits/"..charname..".xml" ),

    Asset( "IMAGE", "images/selectscreen_portraits/"..charname..".tex" ), --单机选人界面
    Asset( "ATLAS", "images/selectscreen_portraits/"..charname..".xml" ),

    Asset( "IMAGE", "images/selectscreen_portraits/"..charname.."_silho.tex" ), --单机未解锁界面
    Asset( "ATLAS", "images/selectscreen_portraits/"..charname.."_silho.xml" ),

    Asset( "IMAGE", "bigportraits/"..charname..".tex" ), --人物大图（方形的那个）
    Asset( "ATLAS", "bigportraits/"..charname..".xml" ),

	Asset( "IMAGE", "images/map_icons/"..charname..".tex" ), --小地图
	Asset( "ATLAS", "images/map_icons/"..charname..".xml" ),

	Asset( "IMAGE", "images/avatars/avatar_"..charname..".tex" ), --tab键人物列表显示的头像
    Asset( "ATLAS", "images/avatars/avatar_"..charname..".xml" ),

	Asset( "IMAGE", "images/avatars/avatar_ghost_"..charname..".tex" ),--tab键人物列表显示的头像（死亡）
    Asset( "ATLAS", "images/avatars/avatar_ghost_"..charname..".xml" ),

	Asset( "IMAGE", "images/avatars/self_inspect_"..charname..".tex" ), --人物检查按钮的图片
    Asset( "ATLAS", "images/avatars/self_inspect_"..charname..".xml" ),

	Asset( "IMAGE", "images/names_"..charname..".tex" ),  --人物名字
    Asset( "ATLAS", "images/names_"..charname..".xml" ),

    Asset( "IMAGE", "bigportraits/"..charname.."_none.tex" ),  --人物大图（椭圆的那个）
    Asset( "ATLAS", "bigportraits/"..charname.."_none.xml" ),

    Asset( "IMAGE", "images/yunlistinv.tex" ),
    Asset( "ATLAS", "images/yunlistinv.xml" ),
    Asset( "IMAGE", "images/yunli_background.tex" ),
    Asset( "ATLAS", "images/yunli_background.xml" ),
    Asset( "IMAGE", "images/i26sticon.tex" ),
    Asset( "ATLAS", "images/i26sticon.xml" ),


    Asset( "IMAGE", "images/iii/i26_skillpoint.tex" ),
    Asset( "ATLAS", "images/iii/i26_skillpoint.xml" ),

    Asset("ANIM", "anim/i26spui.zip"),

    Asset("SOUNDPACKAGE", "sound/i26yl.fev"),
    Asset("SOUND", "sound/i26yl.fsb"),
}


local stis = {
    "skill1", "skill2", "skill3", "skill4", "skill5", "i26_skill6",
    "i26_skill_d1",
    "i26_skill_t1", "i26_skill_t2", "i26_skill_t3",
    "i26_skill_l1", "i26_skill_l2", "i26_skill_l3", "i26_skill_l4",
    "i26_skill_r1", "i26_skill_r2", "i26_skill_r3", "i26_skill_r4",
}
for k,v in pairs(stis) do
    -- table.insert(Assets, Asset( "IMAGE", "images/st/"..v..".tex" ))
    -- table.insert(Assets, Asset( "ATLAS", "images/st/"..v..".xml" ))
    RegisterInventoryItemAtlas("images/yunlistinv.xml", v..".tex")  --不清楚有没有用，总之图片显示了先不动这里了喵 Ou<
end

local require = GLOBAL.require
local STRINGS = GLOBAL.STRINGS

GLOBAL.PREFAB_SKINS[charname] = {   --修复人物大图显示
    charname.."_none",
}

require "utils/recipe_util"

AddMinimapAtlas("images/map_icons/"..charname..".xml")  --增加小地图图标

--增加人物到mod人物列表的里面 性别为女性（MALE, FEMALE, ROBOT, NEUTRAL, and PLURAL）
AddModCharacter(charname, "FEMALE")

AddReplicableComponent("i26skill")
--注册贴图
RegisterInventoryItemAtlas("images/iii/i26_laotie.xml", "i26_laotie.tex")
--imagename = "i26_laotie_0"


modimport("scripts/i26main/constants")
modimport("scripts/utils/recipe_util")
modimport("scripts/i26main/tuning")
modimport("scripts/i26main/strings")
modimport("scripts/i26main/actions")
modimport("scripts/i26main/recipe")
modimport("scripts/i26main/sg")
modimport("scripts/i26main/rpc")
modimport("scripts/i26main/ui")
--联动/兼容mod
modimport("scripts/i26main/link")

for k, v in pairs({
	"components/locomotor",
    "components/health",
    "components/combat",
    "components/reticule",
    "components/temperature",
    "components/builder",
    "components/burnable",
    "stategraphs/wilson",
    "actions",
}) do
	modimport("posi26/"..v)
end
-------------
modimport("scripts/widgets/i26_widgetcreation.lua") -- UI
--------------
-- Prefab --
local function hook_rzw(inst)
    inst:AddTag("i26rzjc")
end
for k,v in pairs(TUNING.I26RZW) do
    AddPrefabPostInit(k, hook_rzw)
end


-- cook --
    local CookerRecipe = {
        test = function(cooker, names, tags)        --甜味剂 树枝 果度>=1  无肉
            return not tags.meat and not tags.monster
            and tags.inedible and tags.sweetener and tags.fruit and tags.fruit >= 1
        end,
        foodtype = FOODTYPE.GOODIES,
        health = 25,
        hunger = 5,
        perishtime = TUNING.PERISH_PRESERVED,    --20天
        sanity = 5,
        cooktime = .25,

        name = "i26_food",
        weight = 1,
        priority = 10,
        overridebuild = "i26foods",
        potlevel = "low",
        cookbook_category = "cookpot",
    }

    AddCookerRecipe("cookpot", CookerRecipe)
    AddCookerRecipe("portablecookpot", CookerRecipe)
    AddCookerRecipe("archive_cookpot", CookerRecipe)
--
--- 技能树 ----
    local skilltree_defs = require('prefabs/skilltree_defs')
    local BuildSkillsData = require('prefabs/skilltree_yunli')
    if BuildSkillsData then
        local data = BuildSkillsData(skilltree_defs.FN)
        if data then
            skilltree_defs.CreateSkillTreeFor('yunli', data.SKILLS)
            skilltree_defs.SKILLTREE_ORDERS['yunli'] = data.ORDERS
        end
    end

    local OldGetSkilltreeBG = GLOBAL.GetSkilltreeBG
    GLOBAL.GetSkilltreeBG = function(imagename, ...)
        if imagename == 'yunli_background.tex' then
            return 'images/yunli_background.xml'
        else
            return OldGetSkilltreeBG(imagename, ...)
        end
    end
    local old_get_icon = GetSkilltreeIconAtlas
    function GLOBAL.GetSkilltreeIconAtlas(imagename, ...)
        if imagename ~= nil and imagename:find('i26')
        then
            return "images/yunlistinv.xml"
        else
            return old_get_icon(imagename, ...)
        end
    end


    local stcostt = {
        i26_skill_d1 = 5,
        i26_skill_l1 = 3,
        i26_skill_r1 = 3,
        i26_skill6 = 3,
    }
    local function hook_skilltreedata(self)
        local oldfn = self.GetAvailableSkillPoints
        self.GetAvailableSkillPoints = function(self, characterprefab, ...)
            if characterprefab and characterprefab == "yunli" then
                local total = 0
                local skills = self.activatedskills[characterprefab]
                if skills then
                    for k, v in pairs(skills) do
                        local val = stcostt[k] ~= nil and stcostt[k] or 1
                        total = total + val
                    end
                end
                return self:GetPointsForSkillXP(self:GetSkillXP(characterprefab)) - total
            end
            return oldfn(self, characterprefab, ...)
        end
    end
    AddClassPostConstruct("skilltreedata", hook_skilltreedata)
--
-- debug

function _G.c_laigelaotie(damage, planardamage, def, planardef)
    local player = ConsoleCommandPlayer()
    if player ~= nil and player.components.inventory ~= nil then
        local laotie = SpawnPrefab("i26_laotie")
        if laotie == nil then return end
        local i26egotool = laotie.components.i26egotool
        if i26egotool == nil then return end
        i26egotool.damage = damage or 30
        i26egotool.planardamage = planardamage or 0
        i26egotool.def = def or .1
        i26egotool.planardef = planardef or 2
        i26egotool:ReSet()
        player.components.inventory:GiveItem(laotie, nil, player:GetPosition())
    end
end
